package com.lcb.manager.repository;

import com.lcb.manager.entity.ChemicalProductOutput;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ChemicalProductOutputRepository extends JpaRepository<ChemicalProductOutput, Integer> {

    @Query(value = "select * from chemical_product_output where year(`date`) = ?1 and month(`date`) = ?2 ",
            countQuery = "select count(*) from chemical_product_output where year(`date`) = ?1 and month(`date`) = ?2 ",
            nativeQuery = true)
    Page<ChemicalProductOutput> findByDateOrderByDateAsc(String year, String month, Pageable pageable);

    Page<ChemicalProductOutput> findByOrderByDateAsc(Pageable pageable);

    @Query(value = "select * from chemical_product_output where year(`date`) = ?1 and month(`date`) = ?2 order by `date` asc ", nativeQuery = true)
    List<ChemicalProductOutput> findByMonth(int year, int month);

    @Query(value = "select * from chemical_product_output where year(`date`) = ?1 order by `date` asc ", nativeQuery = true)
    List<ChemicalProductOutput> findByYear(int year);
}
